Public Class CounterForm

  Dim WithEvents _counter As dotNetTips.Utility.Counter

  Private Sub CreateCounterButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CreateCounterButton.Click

    Me.OutputLabel.Text = String.Empty

    If dotNetTips.Utility.ValidationHelper.IsValidNumber(Me.SeedTextBox.Text) Then
      Me._counter = New dotNetTips.Utility.Counter(1, Integer.Parse(Me.SeedTextBox.Text), 1, 256)
    Else
      Me._counter = New dotNetTips.Utility.Counter()
    End If

    Me.OutputLabel.Text = Me._counter.Value.ToString

  End Sub

  Private Sub Counter_Valuechanged(ByVal sender As Object, ByVal e As dotNetTips.Utility.CounterChangedEventArgs) Handles _counter.Valuechanged
    Me.OutputLabel.Text = e.NewValue.ToString
  End Sub

  Private Sub IncrementButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles IncrementButton.Click

    If dotNetTips.Utility.ValidationHelper.IsValidNumber(Me.IncrementTextBox.Text) Then
      Me._counter.Increment(Integer.Parse(IncrementTextBox.Text))
    Else
      Me._counter.Increment()
    End If


  End Sub

  Private Sub DecrementButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DecrementButton.Click

    If dotNetTips.Utility.ValidationHelper.IsValidNumber(Me.DecrementTextBox.Text) Then
      Me._counter.Decrement(Integer.Parse(DecrementTextBox.Text))
    Else
      Me._counter.Decrement()
    End If

  End Sub

  Private Sub StepButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StepButton.Click

    If dotNetTips.Utility.ValidationHelper.IsValidNumber(Me.StepTextBox.Text) Then
      Me._counter.Step = Integer.Parse(StepTextBox.Text)
    End If

  End Sub

  Private Sub ResetButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ResetButton.Click
    Me._counter.Reset()
  End Sub
End Class